package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书！");
        System.out.println("请输入你要添加的书名、作者、类型、价格：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        String author = sc.nextLine();
        String type = sc.nextLine();
        double price = sc.nextDouble();

        Book book = new Book(name,author,type, price);
        int currentSize = bookList.getUseSize();
        for (int i = 0; i < currentSize; i++) {
          Book temp = bookList.getBooks(i);
            if (temp.getName().equals(name)) {
                System.out.println("该书已存在，添加失败！");
                return;
            }
        }
        bookList.setBooks(book, currentSize);
        bookList.setUseSize(currentSize + 1);
    }
}
